<?php
namespace Home\Controller;

class IndexController extends BaseController {
    //维修介绍
    public function index(){
        //大分类
        if($_GET['cat_id']){
            $first=M('article_cat')->where('cat_id='.$_GET['cat_id'])->find();
            $cat_id=$_GET['cat_id'];
            $ty=$_GET['cat_id'];
        }else{
            $first=M('article_cat')->where('parent_id=0')->order('sort_order desc')->find();
            $cat_id=$first['cat_id'];
            $ty=$first['cat_id'];
        }
        //查询这个下面的小分类
        $article_cat=M('article_cat')->where('parent_id='.$first['cat_id'])->order('sort_order desc')->select();
        if($article_cat){
            if($_GET['id']){
               $find=M('article')->where('cat_id='.$_GET['id']." and is_open=1")->find();
              
            }else{
                $find=M('article')->where('cat_id='.$article_cat[0]['cat_id']." and is_open=1")->find();
               
            }
            $find['content']=htmlspecialchars_decode($find['content']);

        }else{
            $article_cat=array();
        }
        $this->assign('article_cats',$article_cat);
        $this->assign('ty',$ty);
        $this->assign('cat_id',$cat_id);
        $this->assign('find',$find);
        //查询底部的分类
        $cate=M('article_cat')->where('parent_id=0')->order('sort_order desc')->select();
        $this->assign('cate',$cate);
        $this->assign('article',$article);
        $this->display();
    }

}